package com.example.dao;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.example.domain.Term;

/**
 * @author 袁小弘
 * @describe 学期服DAO接口
 * @date 2020-01-01
 */
@Repository
public interface TermDao extends JpaRepository<Term, Integer> {

    @Transactional
    @Modifying
    int deleteByTermId(Integer termId);

    List<Term> findByTermId(Integer termId);

    @Transactional
    @Modifying
    int deleteByTermIdIn(List<Integer> listId);

    List<Term> findByTermNameLike(String termName);

    List<Term> findByTermDurationLike(String termDuration);

    @Query(nativeQuery = true, value = "SELECT term_Id,termName FROM term")
    List<Map<String, Object>> findAllTermNameAndId();

}
